import oracle.jdbc.OracleTypes;
import oracle.jdbc.oracore.OracleType;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;

public class TestDemo {
    public static Connection getConn() throws Exception {
        Class.forName("oracle.jdbc.driver.OracleDriver");

        Connection connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521/orcl","lei","root");

        return connection;
    }

    public void getSal() throws Exception {
        Connection connection = getConn();

        CallableStatement cs = connection.prepareCall("{call p_yearsal(?,?)}");
        cs.setInt(1,7788);
        cs.registerOutParameter(2, OracleTypes.NUMBER);
        cs.execute();

        System.out.println(cs.getInt(2));
    }

    public void getfunction() throws Exception {
        Connection connection = getConn();

        CallableStatement cs = connection.prepareCall("{?=call f_yearsal(?)}");
        cs.setInt(2,7788);
        cs.registerOutParameter(1, OracleTypes.NUMBER);
        cs.execute();

        System.out.println(cs.getInt(1));
    }

    public static void main(String[] args) throws Exception {
       /* System.out.println(TestDemo.getConn());*/
       /* new TestDemo().getSal();*/
        new TestDemo().getfunction();
    }
}
